#include "Window.h"
//---------------------------------------------------------------------------------------------//
HINSTANCE g_hInstance;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

const int wWidth = 800;
const int wHeight = 600; 
//---------------------------------------------------------------------------------------------//
ATOM Window::Register()
{
	WNDCLASS wc;
	
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hInstance = g_hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = TEXT("MyWindow");
    wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpszMenuName = TEXT("MyWindow's title!");
	
	return RegisterClass(&wc); 
}
//---------------------------------------------------------------------------------------------//
bool Window::Create()
{
	if (Register() == 0)
		return false;
	
	hwnd = CreateWindow(TEXT("MyWindow"), TEXT("MyWindow's title!"), WS_OVERLAPPEDWINDOW, 10, 10, wWidth, wHeight, NULL, NULL, g_hInstance, NULL );
	ShowWindow(hwnd, SW_SHOW);
	UpdateWindow(hwnd);

	return true;
}
//---------------------------------------------------------------------------------------------//
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
{
	switch(message)
	{
		case WM_DESTROY:
		case WM_QUIT:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, message, wparam, lparam);
	}
	return 0;
	
}
//---------------------------------------------------------------------------------------------//
HWND Window::GetHwnd()
{
	return hwnd;
}